home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / EmulationProcess.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  2KB  |  121 lines

  1. /*
  2. **    EmulationProcess.c
  3. **
  4. **    Terminal emulation process
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16. STATIC struct Process *EmulationProcess;
  17.  
  18. STATIC VOID SAVE_DS
  19. EmulationProcessEntry(VOID)
  20. {
  21.     if(TerminalQueue = CreateMsgQueue(NULL,40))
  22.     {
  23.         struct MsgQueue    *Queue;
  24.         struct DataMsg *Msg;
  25.         ULONG Mask;
  26.         BOOL Done;
  27.  
  28.         EmulationProcess = (struct Process *)FindTask(NULL);
  29.  
  30.         Signal((struct Task *)ThisProcess,SIG_HANDSHAKE);
  31.  
  32.         Queue = TerminalQueue;
  33.  
  34.         Mask = SIG_KILL | TerminalQueue->SigMask;
  35.  
  36.         Done = FALSE;
  37.  
  38.         do
  39.         {
  40.             if(Wait(Mask) & SIG_KILL)
  41.             {
  42.                 Forbid();
  43.  
  44.                 TerminalQueue = NULL;
  45.  
  46.                 Permit();
  47.  
  48.                 break;
  49.             }
  50.  
  51.             ObtainSemaphore(&TerminalSemaphore);
  52.  
  53.             ClearCursor();
  54.  
  55.             while(Msg = GetMsgItem(TerminalQueue))
  56.             {
  57.                     /* Remember the data. */
  58.  
  59.                 if(RememberOutput)
  60.                     RememberOutputText(Msg->Data,Msg->Size);
  61.  
  62.                 (*ConProcessData)(Msg->Data,Msg->Size);
  63.  
  64.                 DeleteMsgItem((struct MsgItem *)Msg);
  65.  
  66.                 if(SetSignal(0,0) & SIG_KILL)
  67.                 {
  68.                     Forbid();
  69.  
  70.                     TerminalQueue = NULL;
  71.  
  72.                     Permit();
  73.  
  74.                     Done = TRUE;
  75.  
  76.                     break;
  77.                 }
  78.             }
  79.  
  80.             DrawCursor();
  81.  
  82.             ReleaseSemaphore(&TerminalSemaphore);
  83.         }
  84.         while(!Done);
  85.  
  86.         while(Msg = GetMsgItem(Queue))
  87.             DeleteMsgItem((struct MsgItem *)Msg);
  88.  
  89.         DeleteMsgQueue(Queue);
  90.     }
  91.  
  92.     Forbid();
  93.  
  94.     EmulationProcess = NULL;
  95.  
  96.     Signal((struct Task *)ThisProcess,SIG_HANDSHAKE);
  97. }
  98.  
  99. VOID
  100. DeleteEmulationProcess()
  101. {
  102.     ShakeHands((struct Task *)EmulationProcess,SIG_KILL);
  103. }
  104.  
  105. BOOL
  106. CreateEmulationProcess()
  107. {
  108.     if(!EmulationProcess)
  109.     {
  110.         StartProcessWaitForHandshake("term Emulation Process",(TASKENTRY)EmulationProcessEntry,
  111.             NP_StackSize,    8000,
  112.             NP_WindowPtr,    Window,
  113.         TAG_DONE);
  114.     }
  115.  
  116.     if(EmulationProcess)
  117.         return(TRUE);
  118.     else
  119.         return(FALSE);
  120. }
  121.